package com.sphd.emanu.activity.finance;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.sphd.emanu.R;
import com.sphd.emanu.activity.financestaff.FinancestaffActivity;
import com.sphd.emanu.activity.moneymessage.MoneyMessageActivity;
import com.sphd.emanu.activity.search.SearchActivity;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.mvp.MVPBaseActivity;
import com.sphd.emanu.pojo.HomeFragmentInfo;
import com.sphd.emanu.pojo.login.User;
import com.sphd.emanu.view.dataround.DataRound;
import com.sphd.emanu.view.shade.FanImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 工作台----财务模块
 *
 * @Author Hu
 * @Time 2017/5/15 -- 11:07.
 * @Email 87683202@qq.com
 */
public class FinanceActivity extends MVPBaseActivity<FinanceContract.View, FinancePresenter> implements FinanceContract.View {

    @BindView(R.id.finance_search)
    TextView financeSearch;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.round_arc_radian)
    DataRound dataRoundView;
    @BindView(R.id.btn_in)
    Button btnIn;
    @BindView(R.id.balance_now_image)
    FanImageView balanceNowImage;
    @BindView(R.id.balance_lastmonth_image)
    FanImageView balanceLastmonthImage;
    @BindView(R.id.today_income_image)
    FanImageView todayIncomeImage;
    @BindView(R.id.today_spending_image)
    FanImageView todaySpendingImage;
    Intent intent;
    Bundle bundle;
    User user;
    @BindView(R.id.today_money)
    TextView todayMoney;
    @BindView(R.id.last_in_text)
    TextView lastInText;
    @BindView(R.id.last_out_text)
    TextView lastOutText;
    @BindView(R.id.today_in_money)
    TextView todayInMoney;
    @BindView(R.id.today_out_money)
    TextView todayOutMoney;
    @BindView(R.id.last_month_money)
    TextView lastMonthMoney;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_finance);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        intent = getIntent();
        bundle = intent.getExtras();
        user = (User) bundle.getSerializable(Constant.USER_ENTITY);
        setTitleBar(toolbar, "天津贝塔科技公司");

        addData();
    }

    private void addData() {
        showProgressDialog();
        mPresenter.financialHomepage(user.getOid());
    }

    @Override
    public void setBeanBack(HomeFragmentInfo homeFragmentInfo) {
        dissProgressDialog();
        todayMoney.setText(homeFragmentInfo.getBalance() + "");
        todayInMoney.setText(homeFragmentInfo.getTodayCredit() + "");
        todayOutMoney.setText(homeFragmentInfo.getTodayDebit() + "");

        lastMonthMoney.setText(homeFragmentInfo.getPreviousBalance() + "");
        dataRoundView.setArcRadian((float) getAngle(homeFragmentInfo.getPreviousCredit(),
                homeFragmentInfo.getPreviousDebit()));
        lastInText.setText(homeFragmentInfo.getPreviousCredit() + "");
        lastOutText.setText(homeFragmentInfo.getPreviousDebit() + "");

    }

    public double getAngle(double d1, double d2) {
        if (d1 == 0 || d2 == 0) {
            return 0;
        } else {
            return d2 * 360 / (d1 + d2);
        }

    }

    @OnClick({R.id.balance_now_image, R.id.balance_lastmonth_image, R.id.today_income_image, R.id.today_spending_image, R.id.btn_in, R.id.finance_search})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.balance_now_image:
                //跳转到本月余额
                bundle.putInt(Constant.R_ID, R.id.balance_now_image);
                bundle.putBoolean(Constant.ShowIncome, true);//传递是否显示收入
                bundle.putBoolean(Constant.ShowExpend, true);//传递是否显示支出
                intent.setClass(context, MoneyMessageActivity.class);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.balance_lastmonth_image:
                //跳转到上月余额
                bundle.putInt(Constant.R_ID, R.id.balance_lastmonth_image);
                bundle.putBoolean(Constant.ShowIncome, true);//传递是否显示收入
                bundle.putBoolean(Constant.ShowExpend, true);//传递是否显示支出
                intent.setClass(context, MoneyMessageActivity.class);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.today_income_image:
                //跳转到今日收入 以后所有界面将只显示收入
                bundle.putInt(Constant.R_ID, R.id.today_income_image);
                bundle.putBoolean(Constant.ShowIncome, true);//传递是否显示收入
                bundle.putBoolean(Constant.ShowExpend, false);//传递是否显示支出
                intent.setClass(context, MoneyMessageActivity.class);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.today_spending_image:
                //跳转到今日支出 以后所有界面全部显示支出
                bundle.putInt(Constant.R_ID, R.id.today_spending_image);
                bundle.putBoolean(Constant.ShowIncome, false);//传递是否显示收入
                bundle.putBoolean(Constant.ShowExpend, true);//传递是否显示支出
                intent.setClass(context, MoneyMessageActivity.class);
                intent.putExtras(bundle);
                startActivity(intent);
                break;
            case R.id.btn_in:
                //财务人员进入按钮
                intent.setClass(context, FinancestaffActivity.class);
                startActivity(intent);


                break;

            case R.id.finance_search:
                //搜索查看按钮
                intent.setClass(context, SearchActivity.class);
                startActivity(intent);
                break;
        }
    }
}
